/**
 * 
 */
package com.sx.article.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sx.article.dao.IAttachmentDao;
import com.sx.article.entity.ArticleAndAttachmentEntity;
import com.sx.article.entity.AttachmentEntity;
import com.sx.core.BaseDao;
import com.sx.feesunit.exception.SXException;

/**
 * @author Administrator
 *
 */
public class AttachmentDao extends BaseDao implements IAttachmentDao{
	private Log log = LogFactory.getLog(this.getClass());
	
	/* (non-Javadoc)
	 * @see com.sx.article.dao.IAttachmentDao#deleteAttachment(com.sx.article.entity.AttachmentEntity)
	 */
	public boolean deleteAttachment(AttachmentEntity attachemt) {
		boolean flag = false;
		try {
			flag = super.delInfo(attachemt, "Attachment.deleteAttachment");
		} catch (Exception e) {
			log.error("删除附件数据信息",e);
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.dao.IAttachmentDao#findAttachmentInfoById(java.lang.Integer)
	 * 按照ID编号获取附件信息
	 */
	public AttachmentEntity findAttachmentInfoById(Integer id){
		AttachmentEntity attachment = null;
		try {
			AttachmentEntity attach = new AttachmentEntity();
			attach.setFid(id);
			attachment = (AttachmentEntity)super.getSqlMapClientTemplate().queryForObject("Attachment.findAttachmentsInfo",attach);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("按照编号获取附件信息",e);
		}
		return attachment;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.dao.IAttachmentDao#addAttachmentByArticleId(com.sx.article.entity.ArticleAndAttachmentEntity)
	 */
	public boolean addAttachmentByArticleId(ArticleAndAttachmentEntity articleattachment) {
		boolean flag = false;
		try {
			flag = super.delInfo(articleattachment, "Attachment.addAttachmentByArticleId");
		} catch (Exception e) {
			log.error("新增附件关联失败",e);
			// TODO: handle exception
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.dao.IAttachmentDao#deleteAttachmentByArticleId(com.sx.article.entity.ArticleAndAttachmentEntity)
	 */
	public boolean deleteAttachmentByArticleId(
			ArticleAndAttachmentEntity articleattachment) {
		boolean flag = false;
		try {
			flag = super.delInfo(articleattachment, "Attachment.deleteAttachmentByArticleIdAndFileId");
		} catch (Exception e) {
			log.error("删除附件失败",e);
			// TODO: handle exception
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.dao.IAttachmentDao#findAttachmentsInfo(com.sx.article.entity.AttachmentEntity)
	 */
	public List<AttachmentEntity> findAttachmentsInfo(AttachmentEntity attachemt) {
		List<AttachmentEntity> list = null;
		try {
			list = super.getSqlMapClientTemplate().queryForList("Attachment.findAttachmentsInfo",attachemt);
		} catch (Exception e) {
			log.error("查询附件失败",e);
			// TODO: handle exception
		}
		return list;
	}

	/* (non-Javadoc)
	 * @see com.sx.article.dao.IAttachmentDao#findAttachmentsInfoCount(com.sx.article.entity.AttachmentEntity)
	 */
	public String findAttachmentsInfoCount(AttachmentEntity attachemt) {
		String count = null;
		try {
			count = (String)super.getSqlMapClientTemplate().queryForObject("Attachment.findAttachmentsInfoCount",attachemt);
		} catch (Exception e) {
			log.error("查询附件数量失败",e);
			// TODO: handle exception
		}
		return count;
	}

	/**
	 *新增附件信息 
	 **/
	public Integer addAttachment(AttachmentEntity attachment){
		// TODO Auto-generated method stub
		Integer id = null;
		try {
			id = super.addInfo(attachment, "Attachment.addAttachment");
		} catch (Exception e) {
			log.error("新增文章附件信息",e);
			// TODO: handle exception
		}
		return id;
	}

}
